# -*- encoding=utf8 -*-
__author__ = "yangxianming"

from airtest.core.api import *
# ST.PROJECT_ROOT = "E:\AirtestWorkSpace\fuyuanwaiUItest"
# using(r"E:\AirtestWorkSpace\fuyuanwaiUItest\common.air")
# from common import *

auto_setup(__file__)

#拿到设备编号
import sys
args = sys.argv
devicePid = args[4].split("/")[3]
print("--------" + devicePid)
rootArr = args[2].split("\\")
scriptRoot = ""
for i in range(len(rootArr) - 1):
    scriptRoot = scriptRoot + rootArr[i] + "\\"
print("--------" + scriptRoot)

#对更目录下设变编号文件做注册登记操作 1代表在使用  0代表停止使用
with open(scriptRoot + devicePid, 'w') as f:
    f.write('1')
    
using(scriptRoot + "common.air")

from common import *
stop_app("com.alibaba.android.rimet")
start_app("com.alibaba.android.rimet")

try:
    sleep(1.0)
    openKoufu()
    #点管理
    touch(Template(r"tpl1683185726162.png", record_pos=(0.4, 0.816), resolution=(1080, 1920)))
    sleep(1.0)
    touch(Template(r"tpl1683185748610.png", record_pos=(-0.314, -0.136), resolution=(1080, 1920)))
    sleep(1.0)
    touch(Template(r"tpl1683187315293.png", record_pos=(0.236, -0.438), resolution=(1080, 1920)))
    sleep(1.0)
    touch(Template(r"tpl1683185975755.png", target_pos=6, record_pos=(-0.013, -0.35), resolution=(1080, 1920)))
    sleep(1.0)
    text("1")
    touch(Template(r"tpl1683186092905.png", record_pos=(-0.001, 0.095), resolution=(1080, 1920)))
    sleep(1.0)
    touch(Template(r"tpl1683186142385.png", record_pos=(0.426, 0.209), resolution=(1080, 1920)))
    sleep(1.0)
    touch(Template(r"tpl1683188238187.png", target_pos=6,record_pos=(-0.019, 0.366), resolution=(1080, 1920)), duration=0.1)
    sleep(5.0)
    touch(Template(r"tpl1683186245852.png", record_pos=(-0.354, -0.275), resolution=(1080, 1920)), duration=0.1)
    sleep(1.0)
    touch(Template(r"tpl1683186269869.png", record_pos=(0.282, 0.817), resolution=(1080, 1920)))
    sleep(1.0)
    touch(Template(r"tpl1683190856829.png", target_pos=5, resolution=(1080, 1920)))
    sleep(1.0)
    touch(Template(r"tpl1683191229548.png", target_pos=6, record_pos=(-0.02, 0.504), resolution=(1080, 1920)))
    sleep(1.0)
    touch(Template(r"tpl1683191411248.png", record_pos=(-0.253, 0.763), resolution=(1080, 1920)))
    sleep(1.0)
    touch(Template(r"tpl1683191443272.png", record_pos=(0.413, 0.093), resolution=(1080, 1920)))
    touch(Template(r"tpl1683186298678.png", record_pos=(-0.006, 0.795), resolution=(1080, 1920)))
    sleep(1.0)
    touch(Template(r"tpl1683186318215.png", record_pos=(0.001, 0.795), resolution=(1080, 1920)))

    assert_exists(Template(r"tpl1683186339733.png", record_pos=(-0.002, -0.362), resolution=(1080, 1920)), "餐补发放成功")

    
except Exception as e:
    print(e)
finally:
    sleep(1.0)
    stop_app("com.alibaba.android.rimet")
    #完成测试等级设备为0以便被其他脚本使用
    with open(scriptRoot + devicePid, 'w') as f:
        f.write('0')